#include "../include/Configuration.hpp"

Configuration::Configuration(const string &configFilePath)
    : _configFilePath(configFilePath)
{
}

Configuration::~Configuration()
{
}

Configuration *Configuration::getInstance(const string &configFilePath)
{
    if (nullptr == _pconf)
    {
        _pconf = new Configuration(configFilePath);
    }
    return _pconf;
}

map<string, string> &Configuration::getConfigMap()
{
    ifstream ifs(_configFilePath);
    if (!ifs)
    {
        cout << "open file failed" << endl;
#ifdef DEBUG
        cout << "Configuration::getConfigMap()_ifs() failed" << endl;
        cout << "configFilePath: " << _configFilePath << endl;
#endif
    }
    while (ifs)
    {
        // 从配置文件中读取内容，存入_configMap中（类型为 map<string, string>）
        string key, value;
        ifs >> key;
        ifs.get();
        ifs >> value;
        ifs.get();
        _configMap[key] = value;
    }
    ifs.close();
    return _configMap;
}

set<string> &Configuration::getStopWordList()
{
    // TODO
    return _stopWordList;
}

string Configuration::searchConfigMap(const string key)
{
    return _configMap[key];
}

Configuration::AutoRelease Configuration::_ar;
Configuration *Configuration::_pconf = nullptr;